package tool.builder;

import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

import com.winskysoft.frame.MainFrame;

public class ToggleNatureAction implements IObjectActionDelegate {

	private ISelection selection;

	private IWorkbenchPart targetPart;

	private IAction currentAction;

	private IAction chageAction;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction action) {
		
		StructuredSelection ss=(StructuredSelection) selection;
		
		
		JavaProject project=(JavaProject) ss.getFirstElement();
		
		
		MainFrame mainFrame=new MainFrame(project);
		 
		mainFrame.open();
		 
//		try {
//			File file=new File(project.getProject().getParent().getLocation()+"/"+project.getPackageFragments()[0].getPath()+"/js.c");
//			System.out.println(file.getAbsolutePath());
//			System.out.println("/"+project.getProject().getName());
//			IPackageFragmentRoot[] roots=project.getAllPackageFragmentRoots();
//			for(int i=0;i<roots.length;i++){
//				if(roots[i].getPath().toString().startsWith("/"+project.getProject().getName())){
//						for(int j=0;j<roots[i].getChildren().length;j++){
//							System.out.println(roots[i].getChildren()[j].getPath());
//						}
//				}
//				
//			}
//		} catch (JavaModelException e) {
//			e.printStackTrace();
//		}
		
//		System.out.println(project.getProject().getLocation());
//
//		File file=new File("d:/ri.txt");
//		
//		try {
//			FileWriter write=new FileWriter(file);
//			
//			write.write(project.getProject().getLocation()+"");
//			
//			write.flush();
//			write.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
		
		
		
		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action
	 * .IAction, org.eclipse.jface.viewers.ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
		this.selection = selection;
		this.chageAction = action;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.
	 * action.IAction, org.eclipse.ui.IWorkbenchPart)
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		this.targetPart = targetPart;
		this.currentAction = action;
	}

}
